package com.ruoyi.mobile.controller;

import com.ruoyi.mobile.service.*;
import com.ruoyi.mobile.utils.NftResponse;
import com.ruoyi.mobile.utils.Paginator;
import com.ruoyi.mobile.utils.ResponseConstants;
import com.ruoyi.system.api.req.SchoolConsumeReq;
import com.ruoyi.system.api.req.SchoolPayrecordReq;
import com.ruoyi.system.api.req.SchoolStudentReq;
import com.ruoyi.system.api.req.SysUserReq;
import com.ruoyi.system.api.resp.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/usercus")
@Api(tags = "用户耗课模块")
public class UserCustomController {
    @Autowired
    private ISysDeptService sysDeptService;
    @Autowired
    private SchoolClassesService schoolClassesService;
    @Autowired
    private SchoolPayrecordService schoolPayrecordService;
    @Autowired
    private SchoolConsumeService schoolConsumeService;
    @Autowired
    private SchoolStudentService schoolStudentService;

    @ApiOperation(value="获取用户所属学校信息")
    @RequestMapping(value = "/getUserSchoolListByPhone", method = RequestMethod.POST)
    public NftResponse<List<SysDeptResp>> getUserSchoolListByPhone(@RequestBody SysUserReq query) {
        return sysDeptService.getShopListByPhone(query);
    }

    @ApiOperation(value="获取用户所属班级信息")
    @RequestMapping(value = "/getUserClassesListByUserId", method = RequestMethod.POST)
    public NftResponse<List<SchoolClassesResp>> getUserClassesListByUserId(@RequestBody SysUserReq query) {
        return schoolClassesService.getClassesListByUserId(query);
    }

    @ApiOperation(value="获取缴费信息")
    @RequestMapping(value = "/getPayRecords", method = RequestMethod.POST)
    public NftResponse<Paginator<SchoolPayrecorddResp>> getPayRecords(@RequestBody SchoolPayrecordReq query) {
        return schoolPayrecordService.getPayrecordList(query);
    }

    @ApiOperation(value="获取总余额信息")
    @RequestMapping(value = "/getPayRemainder", method = RequestMethod.GET)
    public NftResponse<SchoolPayrecordResp> getPayRemainder(@RequestParam("phone") String phone) {
        return schoolPayrecordService.getPayRemainder(phone);
    }

    @ApiOperation(value="获取耗课信息")
    @RequestMapping(value = "/getConsume", method = RequestMethod.POST)
    public NftResponse<Paginator<SchoolConsumeResp>> getConsume(@RequestBody SchoolConsumeReq query) {
        return schoolConsumeService.getConsumeList(query);
    }

    @ApiOperation(value="获取学生耗课信息")
    @RequestMapping(value = "/getXsConsume", method = RequestMethod.POST)
    public NftResponse<Paginator<SchoolStudentResp>> getXsConsume(@RequestBody SchoolStudentReq query) {
        return schoolStudentService.getStudentConsumeList(query);
    }

    @ApiOperation(value="耗课信息")
    @RequestMapping(value = "/realConsume", method = RequestMethod.POST)
    public NftResponse<Boolean> realConsume(@RequestBody SchoolConsumeReq query) {
        return schoolConsumeService.insertConsumeInfos(query);
    }

    @ApiOperation(value="获取学生列表信息")
    @RequestMapping(value = "/getXsList", method = RequestMethod.POST)
    public NftResponse<List<SchoolStudentResp>> getXsList(@RequestBody SchoolStudentReq query) {
        return schoolStudentService.getStudentList(query);
    }

    @ApiOperation(value="删除缴费信息")
    @RequestMapping(value = "/delPayrecord", method = RequestMethod.POST)
    public NftResponse<Boolean> delPayrecord(@RequestBody SchoolPayrecordReq query) {
        return schoolPayrecordService.delPayById(query.getId());
    }

    @ApiOperation(value="删除耗课信息")
    @RequestMapping(value = "/delConsume", method = RequestMethod.POST)
    public NftResponse<Boolean> delConsume(@RequestBody SchoolConsumeReq query) {
        boolean rtn = schoolConsumeService.removeById(query.getId());
        return new NftResponse<>(ResponseConstants.SUCCESS_CODE, "删除成功", rtn);
    }
}
